/**
 * 光敏电阻实验, 当光线强时, 点亮 LED; 光线暗时, 熄灭 LED
 */
#define LED 13
#define LDR A0

int ldr = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  ldr = analogRead(LDR);
  
  Serial.println(ldr);
  delay(500);
  
  // 光线越强, 电阻越小
  if (ldr < 1000){
    delay(100);
    if (ldr < 1000){
      digitalWrite(LED, HIGH);
    }
  } else {
    digitalWrite(LED, LOW);
  }
}
